/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mscs.cashier.view;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import mscs.data.pojo.Goods;

/**
 *
 * @author Cake
 */
public class TableModelFactory {
    
    public static Vector<String> columnNames = new Vector<String>();
    
    public static DefaultTableModel getSearchGoodsModel() {
        return new MyTableModel(null, SEARCHGOODS_COLUMN_NAMES);
    }
    
    public static DefaultTableModel getSearchSaleRecordModel() {
        return new MyTableModel(null, SEARCHSALERECORD_COLUMN_NAMES);
    }
    
    public static DefaultTableModel getReturnRecordListModel() {
        return new MyTableModel(null, SEARCHRETURNRECORD_COLUMN_NAMES);
    }
    
    public static DefaultTableModel getSaleGoodsModel() {
        return new MyTableModel(null, SALEGOODS_COLUMN_NAMES);
    }
    
    public static DefaultTableModel getReturnGoodsModel() {
        return new MyTableModel(null, RETURNGOODS_COLUMN_NAMES);
    }
   
      public static DefaultTableModel getGiftsModel() {
        return new MyTableModel(null, GIFTS_COLUMN_NAMES);
    }
    
    public  static Vector<String> SEARCHGOODS_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识", "数量", "描述", "销售价格","特价"
            ));
     public  static Vector<String> SEARCHSALERECORD_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识","总额", "日期"
            ));
     public  static Vector<String> SEARCHRETURNRECORD_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识","总额", "日期"
            ));
    
    public static Vector<String> SALEGOODS_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识", "数量", "描述", "销售价格","特价","总价"
            ));
    
    public static Vector<String> RETURNGOODS_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识", "数量", "描述", "销售价格","特价","总价"
            ));
    public static Vector<String> GIFTS_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识", "名称","数量"
            ));
     public static Vector<String> RETURNRECORD_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识", "总额","日期"
            ));
    
    
          public Vector<Vector<String>> toSearchGoodsDataTable(List list) {
    	try {
            Vector<Goods> seList = new Vector(list);
            Vector<Vector<String>> reList = new Vector<Vector<String>>();
            for (Goods goods : seList)
            {
                reList.add((Vector<String>)toSearchGoodsStringArray(goods));
            }
            return reList;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
      
       public Vector<Vector<String>> toSaleDataTable(List list,int num) {
    	try {
            Vector<Goods> seList = new Vector(list);
            Vector<Vector<String>> reList = new Vector<Vector<String>>();
            for(int i=0; i<seList.size(); i++){
                //reList.add((Vector<String>)toSaleStringArray(seList.get(i),numberList.get(i)));
                reList.add((Vector<String>)toSaleStringArray(seList.get(i),num));
            }
            return reList;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
       
      
    
     public List toSearchGoodsStringArray(Goods goods){
        Vector<String> list = new Vector<String>();
        list.add(goods.getId());
        list.add(String.valueOf(goods.getNum()));
        list.add(goods.getDesc());
        list.add(((Double)goods.getSalPrice()).toString());
        return list;
    }
    
    public List toSaleStringArray(Goods goods, int num){
        Vector<String> list = new Vector<String>();
        list.add(goods.getId());
        list.add(String.valueOf(num));
        list.add(goods.getDesc());
        list.add(((Double)goods.getSalPrice()).toString());
        
        list.add("");
        
        list.add(String.valueOf(num*goods.getSalPrice()));
        return list;
    }
   
    
    
    
    
    
    
    
    
    
}

class MyTableModel extends DefaultTableModel{


    public MyTableModel(Vector<Vector<String>> data, Vector<String> columnNames) {
        super(data, columnNames);
        
    }
    
    static DefaultTableModel getSaleGoodsModel() {
        return new MyTableModel(null, SALEGOODS_COLUMN_NAMES);
    }
    
    public static Vector<String> SALEGOODS_COLUMN_NAMES=new Vector(Arrays.asList(
            "标识", "数量", "描述", "销售价格","特价","总价"
            ));
    
    
    public boolean isCellEditable (int row, int column) {
        return false;
    }
     public boolean getColumnSelectionAllowed(){
         return false;
     }

    
}